package org.lvgo.builder.demo1;

/**
 * @author lvgo
 * @version 1.0
 * @Description: 人物角色
 * @date 18-8-21 下午4:37
 */
public class Person {


    private Eyes eyes;
    private Hair hair;
    private Leg leg;

    public Person(Builder builder) {
        this.leg = builder.getLeg();
        this.eyes = builder.getEyes();
        this.hair = builder.getHair();
    }


    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("我是个人");
        if (eyes != null) {
            stringBuilder.append(eyes.getCount()).append("个");
            stringBuilder.append(eyes.getColor()).append("的眼睛");
        }
        if (hair != null) {
            stringBuilder.append(",");
            stringBuilder.append(hair.getColor()).append("的头发");
        }
        if (leg != null) {
            stringBuilder.append(",").append(leg.getCount()).append("条腿");
        }
        return stringBuilder.toString();

    }


    public static class Builder {
        private Eyes eyes;
        private Hair hair;
        private Leg leg;

        public Eyes getEyes() {
            return eyes;
        }

        public void setEyes(Eyes eyes) {
            this.eyes = eyes;
        }

        public Hair getHair() {
            return hair;
        }

        public void setHair(Hair hair) {
            this.hair = hair;
        }

        public Leg getLeg() {
            return leg;
        }

        public void setLeg(Leg leg) {
            this.leg = leg;
        }

        public Builder eyes(int count, String color) {
            this.eyes = new Eyes();
            eyes.setColor(color);
            eyes.setCount(count);
            return this;
        }

        public Builder leg(int count) {
            this.leg = new Leg();
            leg.setCount(count);
            return this;
        }

        public Builder hair(String color) {
            this.hair = new Hair();
            hair.setColor(color);
            return this;
        }

        public Person build() {
            return new Person(this);
        }
    }
}
